/**
 * 师徒积分管理初始化
 */
var MentoringRelationPoints = {
    id: "MentoringRelationPointsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    width: '850px',
    height: '520px'
};

/**
 * 初始化表格的列
 */
MentoringRelationPoints.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工编号', field: 'empCode', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工姓名', field: 'empName', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '积分类型', field: 'integralType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '积分', field: 'integral', visible: true, align: 'center', valign: 'middle',sortable: true},
    ];
};

/**
 * 检查是否选中
 */
MentoringRelationPoints.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        MentoringRelationPoints.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加师徒积分
 */
MentoringRelationPoints.openAddMentoringRelationPoints = function () {
    var index = layer.open({
        type: 2,
        title: '添加师徒积分',
        area: [MentoringRelationPoints.width, MentoringRelationPoints.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/mentoringRelationPoints/mentoringRelationPoints_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看师徒积分详情
 */
MentoringRelationPoints.openMentoringRelationPointsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '师徒积分详情',
            area: [MentoringRelationPoints.width, MentoringRelationPoints.height], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/mentoringRelationPoints/mentoringRelationPoints_update/' + MentoringRelationPoints.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除师徒积分
 */
MentoringRelationPoints.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/mentoringRelationPoints/delete", function (data) {
            Feng.success("删除成功!");
            MentoringRelationPoints.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("mentoringRelationPointsId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询师徒积分列表
 */
MentoringRelationPoints.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    MentoringRelationPoints.table.refresh({query: queryData});
};

/**
 * 打开导入师徒积分数据页面
 */
MentoringRelationPoints.import = function () {
    var index = layer.open({
        type: 2,
        title: '师徒积分',
        area: [MentoringRelationPoints.width, MentoringRelationPoints.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/mentoringRelationPoints/mentoringRelationPoints_import'
    });
    this.layerIndex = index;
};


/**
 * 高级搜索
 */
MentoringRelationPoints.g_search = function () {
    var index = layer.open({
        type: 2,
        skin: 'layui-layer-molv',
        title: '高级搜索',
        area: ['800px', '300px'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/employee/g_search',
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var queryData = window["layui-layer-iframe" + index].Employee.search2();

            MentoringRelationPoints.table.setQueryParams(queryData);
            MentoringRelationPoints.table.refresh();
            MentoringRelationPoints.table.empty();
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    });
    this.layerIndex = index;
};

$(function () {
    var defaultColunms = MentoringRelationPoints.initColumn();
    var table = new BSTable(MentoringRelationPoints.id, "/mentoringRelationPoints/list", defaultColunms);
    table.setPaginationType("client");
    MentoringRelationPoints.table = table.init();
});
